package com.skynet.supervision.common;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.util.List;

@Data
public class PageResults<T> {

    /**
     * 页码
     */
    private long page;

    /**
     * 分页大小
     */
    private long pageSize;

    /**
     * 总数
     */
    private long total;

    /**
     * 分页数据
     */
    private List<T> results;

    public static <T> PageResults<T> of(IPage<T> page) {
        var out = new PageResults<T>();
        out.setPage(page.getCurrent());
        out.setPageSize(page.getSize());
        out.setTotal(page.getTotal());
        out.setResults(page.getRecords());
        return out;
    }

    public static <T> PageResults<T> of(long page, long pageSize, long total, List<T> results) {
        var out = new PageResults<T>();
        out.setPage(page);
        out.setPageSize(pageSize);
        out.setTotal(total);
        out.setResults(results);
        return out;
    }


}
